<template>
  <div class="server-main">
    <el-form :inline="true" v-model="modelData" class="search-form">
      <el-form-item label="模型分类:" class="status">
        <el-select v-model="modelData.modelType">
          <el-option label="全部" value=""></el-option>
          <el-option label="分类模型" value="分类模型"></el-option>
          <el-option label="聚类模型" value="聚类模型"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit(1)">查询</el-button>
      </el-form-item>
    </el-form>
    <div class="server-table">
      <div class="table-title">
        <span class="table-title-text">模型管理</span>
        <el-button type="primary" size="small">导入测试数据</el-button>
      </div>
      <el-table :data="tableList" class="km-table">
        <el-table-column
          type="index"
          label="ID"
          width="50"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="modelName"
          label="模型名称"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="modelType"
          label="模型类型"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="modelVersion"
          label="版本"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="createTime"
          label="上传时间"
          align="center"
        ></el-table-column>
        <!-- <el-table-column
          prop="createUseId"
          label="上传人员"
          align="center"
        ></el-table-column> -->
        <!-- <el-table-column prop="ontologyAllState" label="状态" width="60" align="center">
          <template slot-scope="scope">
            <span>{{ +scope.row.ontologyAllState === 0 ? "启用" : "禁用" }}</span>
          </template>
        </el-table-column> -->
        <el-table-column label="操作" align="center" width="220">
          <template slot-scope="scope">
            <el-link
              :underline="false"
              type="primary"
              class="ontology-edit"
              @click.native.prevent="openEditOntology(scope.row)"
              >配置</el-link
            >
            <el-link
              :underline="false"
              type="primary"
              class="ontology-edit"
              @click.native.prevent="applyRecord(scope.row.modelId)"
              >应用记录</el-link
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="km-pagination"
        background
        :small="true"
        layout="total, prev, pager, next,sizes, jumper"
        :total="total"
        :hide-on-single-page="!total"
        :page-size.sync="modelData.pageSize"
        :pager-count="7"
        :page-sizes="[10, 20, 30]"
        :current-page="modelData.pageNum"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      >
      </el-pagination>
      <!--edialogl- :title="dialogTitle" :visible.sync="dialogVisible" @close="afterDialogClose">
        <el-form :model="dialogForm" :rules="dialogRules" ref="dialogForm" label-position="right" label-width="160px"
          :inline="true">
          <el-form-item label="选择文件:" prop="fileName" v-if="dialogTitle !== '参数配置'">
            <el-upload v-if="!dialogForm.fileName" :before-upload="beforeUpload" :show-file-list="false"
              :http-request="uploadSectionFile">
              <el-button type="primary">选择文件</el-button>
            </el-upload>
            <el-input v-else v-model="dialogForm.fileName" readonly></el-input>
          </el-form-item>
          <el-form-item label="模型名称:">
            <el-input v-model="dialogForm.recommedModel" readonly></el-input>
          </el-form-item>
          <el-form-item label="模型版本号:" prop="modelVersion">
            <el-input v-model="dialogForm.modelVersion"></el-input>
          </el-form-item>
          <el-form-item label="模型类型:" prop="recommedModel">
            <el-select v-model="dialogForm.recommedModel">
              <el-option label="工具模型" value="工具推荐模型"></el-option>
              <el-option label="用例模型" value="用例推荐模型"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="召回率:" prop="recallRate">
            <el-input v-model="dialogForm.recallRate"></el-input>
          </el-form-item>
          <span :style="{height: '30px',lineHeight: '38px'}">%</span>
          <el-form-item label="准确率:" prop="exactRate">
            <el-input v-model="dialogForm.exactRate"></el-input>
          </el-form-item>
          <span :style="{height: '30px',lineHeight: '38px'}">%</span>
          <el-form-item label="最大推荐数量:" prop="maxRecommendCount">
            <el-input v-model="dialogForm.maxRecommendCount"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogDefine(dialogTitle)">确 定</el-button>
        </div>
      </!--edialogl--->
    </div>
  </div>
</template>
<script>
import { mapState, mapMutations } from "vuex";
export default {
  name: "OntologyManagement",
  components: {},
  data: () => {
    return {
      modelData: {
        modelType: "", // 本体名称
        pageNum: 1, // 页码
        pageSize: 10, // 每页条数
      },
      tableList: [], // 本体列表
      total: 0, // 数据总条数
      loading: false,
      dialogFormVisible: false,
      uploadFormVisible: false,
      editOntologyId: null, // 编辑本体的id
      modelId: "",
      dialogVisible: false,
      dialogTitle: "参数配置",
      dialogForm: {
        fileName: "",
        recommedModel: "工具推荐模型",
        modelVersion: "",
        recallRate: "",
        exactRate: "",
        maxRecommendCount: "",
      },
      dialogRules: {
        fileName: [
          {
            required: true,
            message: "请选择文件",
            trigger: "blur",
          },
        ],
        modelVersion: [
          {
            required: true,
            message: "请输入模型版本号",
            trigger: "blur",
          },
        ],
        recallRate: [
          {
            required: true,
            message: "请输入召回率",
            trigger: "blur",
          },
        ],
        exactRate: [
          {
            required: true,
            message: "请输入准确率",
            trigger: "blur",
          },
        ],
        maxRecommendCount: [
          {
            required: true,
            message: "请输入最大推荐数量",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {
    ...mapState({
      containerDom: (state) => state.server.containerDom,
    }),
  },
  created() {
    // 获取本体列表
    this.getModelList();
  },
  methods: {
    ...mapMutations({
      // save_allGraphData: "ontologyModel/save_allGraphData",
      save_ontologyAllId: "ontologyModel/save_ontologyAllId",
    }),
    // 获取事件查询列表
    getModelList() {
      let params = this.modelData;
      this.$axios
        .post(this.$api.resultAnalyse.zehaoObj.modelList, params)
        .then((res) => {
          let data = res.data.data;
          this.tableList = data;
          console.log("wuhu1", this.tableList);
          // this.total = data.total;
          // this.modelData.pageSize = data.pageSize;
          // this.modelData.pageNum = data.pageNum;
          // this.$utils.backtop(this.containerDom);
        })
        .catch((err) => {
          console.error(err);
        });
    },
    // 查询
    onSubmit(pageNum) {
      this.modelData.pageNum = pageNum ? pageNum : this.modelData.pageNum;
      this.getModelList();
    },
    // 修改当前页码
    handleCurrentChange(page) {
      this.modelData.pageNum = page;
      this.getModelList();
    },
    //跳转应用记录
    applyRecord(modelId) {
      this.$router.push({
        path: "/resultAnalyse/modelManagementHistory",
        query: {
          modelId,
        },
      });
    },
    // 跳转详情页
    goDetail(id) {
      this.$router.push(`/ontologyModel/ontologyManagement/edit/${id}`);
      this.save_ontologyAllId(id);
    },

    // 模态框关闭后
    afterDialogClose() {
      this.$refs.dialogForm && this.$refs.dialogForm.resetFields();
      this.$refs.uploadForm && this.$refs.uploadForm.resetFields();
    },
    // 配置
    openEditOntology(row) {
      this.dialogTitle = "参数配置";
      this.dialogVisible = true;
      const { modelId } = row;
      this.modelId = modelId;
    },

    // 取消
    resetDialogForm() {
      this.dialogFormVisible = false;
      this.uploadFormVisible = false;
    },
  },
};
</script>
<style lang="scss" scoped>
.server-main {
  position: relative;

  .search-form {
    // height:60px;
    padding: 0 20px;
  }

  .form-input ::v-deep .el-input {
    width: 250px;
    margin-right: 20px;
  }

  .server-table {
    padding: 20px;

    .table-title {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .table-title-text {
        border-left: 5px solid $--color-primary;
        padding-left: 10px;
      }

      margin-bottom: 10px;
    }
  }

  .ontology-edit {
    padding: 0 10px;
    & + .ontology-edit {
      border-left: 1px solid #dddddd;
    }
  }

  ::v-deep .el-table__append-wrapper {
    padding: 10px;
  }

  ::v-deep .el-dialog {
    width: 500px;
    border-radius: 5px;
  }

  .dialog-inline {
    ::v-deep .el-form-item__content {
      width: 300px;
    }

    button.el-button {
      background-color: $--color-primary !important;
      color: #fff !important;
      line-height: 1.2;
    }
  }
  .upload-hint {
    font-size: 12px;
    color: #aaa;
    text-align: center;
    line-height: 40px;
  }
}
</style>
